/////////////////
//  PREAMBLE  //
////////////////


/*	program:	Analysis-5-Congressional-Ideal-Points.do
	author:		David Bateman */

/******************************************************************************/
/***                                                                        ***/
/*** File examines the impact of suffrage reform on congressional ideal     ***/
/*** points. These were estimated using the voteview roll call files, with 	***/
/*** the IDEAL program in pscl in R (Clinton, Jackman, Rivers 2004).        ***/
/*** The scores were then made comparable across chambers using the         ***/
/*** TurboADA method described in Groseclose et al (1999)                   ***/
/***                                                                        ***/
/*** For reforming states, the month and year in which the election was held***/
/*** is identified. Elections to Congress were often staggered rather than  ***/
/*** all held in November of an even-numbered year. This way, all           ***/
/*** observed members can be coded according to the franchise regime in     ***/
/*** place when they were elected.                                          ***/
/***                                                                        ***/
/******************************************************************************/

clear all

cd "..\..\Dataverse\"
set more off

*** Load ideal point data and correct some of the at-large versus one-member district codes.
use "Data\adjusted-house-ideal-points.dta", clear
replace cd = 98 if cd==1 & icpsrstate==11 
replace cd = 98 if cd==99 & icpsrstate==3 & congress==3 
replace cd = 98 if cd==99 & icpsrstate==44 & congress==20 
replace cd = 98 if cd==99 & icpsrstate==46 & congress==33 
replace cd = 98 if cd==1 & icpsrstate==24 & (congress>=8 & congress<=12) 
replace cd = 98 if cd==1 & icpsrstate==22 & (congress>=14 & congress<=17) 
replace cd = 98 if cd==1 & icpsrstate==21 & (congress>=15 & congress<=22) 
replace cd = 98 if cd==1 & icpsrstate==46 & (congress>=15 & congress<=29) 
replace cd = 98 if cd==1 & icpsrstate==41 & (congress>=16 & congress<=17) 
replace cd = 98 if cd==1 & icpsrstate==34 & (congress>=17 & congress<=29) 
replace cd = 98 if cd==1 & icpsrstate==42 & (congress>=23 & congress<=32) 
replace cd = 98 if cd==1 & icpsrstate==23 & (congress>=24 & congress<=27) 
replace cd = 98 if cd==1 & icpsrstate==43 & (congress>=29 & congress<=43) 
replace cd = 98 if cd==1 & icpsrstate==72 & (congress>=35 & congress<=52) 
replace cd = 98 if cd==1 & icpsrstate==32 & (congress>=36 & congress<=42) 

*** Merge in a datafile for each unique district, ie., each district with the same
*** underlying county or town composition. This will form the basis for the panel
*** structure for some of the analyses below.
merge m:1 congress icpsrstate cd using "Data\unique_districts.dta", gen(merge1)
drop if merge1!=3

*** Merge in a dataset showing the date of election for each state delegation.
merge m:1 congress icpsrstate using "Data\congress-election-dates.dta", keepusing(date date1)
gen year = year(date1)
gen time = year-1787
gen time_2 = time^2
gen decade = int(year/10)*10

*** Merge in reduced suffrage database. This will be used for supplemental material.
merge m:1 icpsrstate year using "Data\Suffrage-Reduced.dta", gen(merge2)
drop if merge2==2
drop merge1 merge2

gen category_prop_tax = 0 if whnb_property_effective==0 & whnb_taxpayer==0
replace category_prop_tax = 1 if whnb_taxpayer==1 
replace category_prop_tax = 2 if whnb_property_effective==1 

capture label drop category_prop_tax
label define category_prop_tax 0 "Residency"
label define category_prop_tax 1 "Tax", add
label define category_prop_tax 2 "Property", add
label values category_prop_tax category_prop_tax

*** When did suffrage reform go into effect?
gen reform 		= . 
replace reform	= -61197 if state=="DE" 
replace reform	= -57351 if state=="MD" 
replace reform	= -55563 if state=="NJ" 
replace reform	= -54434 if state=="SC" 
replace reform	= -51683 if state=="CT" 
replace reform	= -50618 if state=="MA" 
replace reform	= -50344 if state=="NY" 
replace reform	= -47300 if state=="VA" 
replace reform	= -42643 if state=="RI" 
replace reform	= -41637 if state=="LA"

*** Generate a variable indicating which states made a substantial change
gen refState	= (icpsrstate==11 | icpsrstate==52 | icpsrstate==12 | icpsrstate==48 | icpsrstate==1 | icpsrstate==3 |icpsrstate==13 | icpsrstate==45 | icpsrstate==40 | icpsrstate==5)
*** For graphing purposes, want to have the full state name of reforming states.
replace state = "Delaware" if state=="DE"
replace state = "Maryland" if state=="MD"
replace state = "New Jersey" if state=="NJ"
replace state = "South Carolina" if state=="SC"
replace state = "Connecticut" if state=="CT"
replace state = "Massachusetts" if state=="MA"
replace state = "New York" if state=="NY"
replace state = "Virginia" if state=="VA"
replace state = "Rhode Island" if state=="RI"
replace state = "Louisiana" if state=="LA"

*** Identify states as high, medium, or low thresholds, including dates of reform
gen category 	 = 1 if (date1<-61197) & icpsrstate==11	// Constitution goes into effect on June 12, 1792.
replace category = 1 if (date1<-57351) & icpsrstate==52 // Amendment passed second time on 23rd Dec 1803
replace category = 1 if (date1<-55563) & icpsrstate==12	// Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act."
replace category = 2 if (date1<-54434) & icpsrstate==48	// Constitutional amendment ratified on December 19, 1810.
replace category = 1 if (date1<-51585) & icpsrstate==1 	// Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a modification of the existing election law was passed, repealing the "stand-up" law. A constitutional convention would be called in 1818 on a broad franchise.
replace category = 1 if (date1<-50618) & icpsrstate==3 	// Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace category = 1 if (date1<-50344) & icpsrstate==13	// Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace category = 1 if (date1<-39800) & icpsrstate==40 // Constitution went into effect on January 12, 1851
replace category = 2 if (date1<-47300) & icpsrstate==40 // Constitution ratified and went into effect on July 1 1830
replace category = 2 if (date1<-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1<-41637) & icpsrstate==45	// Constitution went into effect in January 1846
replace category = 0 if category==.

*** Set direction of ideal points
replace adjust_d1 = adjust_d1*-1

label define category 2 "High Qualification" 1 "Medium Qualification"  0 "Low Qualification"
label values category category

*** Correct some missing party data
replace partycode=1 if icpsrlegis==5768 & congress==18
replace partycode=1 if icpsrlegis==128 & congress==18
replace partycode=1 if icpsrlegis==9903 & congress==18
replace partycode=100 if icpsrlegis==530 & congress==18
replace partycode=1 if icpsrlegis==6866 & congress==18
replace partycode=1 if icpsrlegis==5491 & congress==18
replace partycode=1 if icpsrlegis==2797 & congress==18
replace partycode=1 if icpsrlegis==7789 & congress==18
replace partycode=1 if icpsrlegis==6323 & congress==18
replace partycode=1 if icpsrlegis==9632 & congress==18
replace partycode=1 if icpsrlegis==9029 & congress==18
replace partycode=1 if icpsrlegis==8997 & congress==18
replace partycode=1 if icpsrlegis==6094 & congress==18
replace partycode=100 if icpsrlegis==2926 & congress==18
replace partycode=100 if icpsrlegis==1186 & congress==18
replace partycode=100 if icpsrlegis==2873 & congress==18
replace partycode=100 if icpsrlegis==9886 & congress==18
replace partycode=100 if icpsrlegis==4298 & congress==18
replace partycode=1 if icpsrlegis==990 & congress==18
replace partycode=1 if icpsrlegis==8894 & congress==18
replace partycode=1 if icpsrlegis==2242 & congress==18
replace partycode=100 if icpsrlegis==5560 & congress==18
replace partycode=1 if icpsrlegis==6852 & congress==18
replace partycode=1 if icpsrlegis==9829 & congress==18

*** Identify which members are Democrats and affiliated parties (Federalists or affiliated/successor parties)
gen demFull = (partycode==100 | partycode==555 | partycode==108 | partycode==329 | partycode==346) | (partycode==200 & year<=1830)
gen fedFull	= (partycode==29 | partycode==1 | partycode==22 | partycode==603 | partycode==275	///
			| partycode==310 | partycode==25 | partycode==403 | partycode==26 | partycode==333 | partycode==444 | partycode==888)	///
			| (partycode==200 & year>=1850)

*** Generate state-by-state figures of how ideal points changed after franchise
*** reform. 			
preserve
	gen group 		= state
	replace group	= "All Other States" if refState==0 

	*** Set up a "year zero" for graphing how ideal points changed before and
	*** after reform across states.
	gen year_zero = .
	bys icpsrstate (date1): replace year_zero = date1 - reform
	*** Decide which of Virginia's two reforms will be included in the figure.
	replace year_zero=. if icpsrs==40 & date1>=-39800
	gen treatment = year_zero>=0
	
	
	tw (scatter adjust_d1 year_zero if refState!=0 & adjust_d1<=3 & adjust_d1>=-3 & year_zero>=-5475 & year_zero<=5475, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
		(lpolyci adjust_d1 year_zero if refState!=0 & year_zero<0 & year_zero>=-5475, clcol(black))	///
		(lpolyci adjust_d1 year_zero if refState!=0 & year_zero>=0 & year_zero<=5475, clcol(black)) ///
		, xline(0, lw(thin) lp(dash) lc(black))				///
		graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) 	///
				xlab(-5110 "-14" -4380 "-12" -3650 "-10" -2920 "-8" -2190 "-6" -1460 "-4" -730 "-2" 0 "0"	///
				730 "2" 1460 "4" 2190 "6" 2920 "8" 3650 "10"  4380 "12" 5110 "14", labsize(vsmall) format(%tdCCYY)) ///
				xtitle("") title("Reforming States", size(small) col(black) box bexpand) note("") legend(off) name(combined_ideal, replace)
	
	levelsof group, local(levels)
	foreach x in `levels' {
		local y = subinstr("`x'"," ","",.) 

		di "`x'"
		summ reform if group=="`x'"
		local k = r(min)
		if "`x'" == "Rhode Island"  {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Delaware" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Maryland" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "New Jersey" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "South Carolina" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==2 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Connecticut" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Massachusetts" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}		
		else if "`x'" == "New York" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Virginia" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(-47361 -39800, lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}		
		else if "`x'" == "Louisiana" {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==1 & group=="`x'", clcol(black))	///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				xline(`k', lw(thin) lp(dash) lc(black))			///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else {
			tw (scatter adjust_d1 date1 if group=="`x'" & adjust_d1<=3 & adjust_d1>=-3,  msy(o) jitter(.8) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci adjust_d1 date1 if category==0 & group=="`x'", clcol(black)), ///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(-3 3)) ylabel(none, angle(h) labsize(vsmall) nogrid) ///
					xlab(-61878 "1790" -58225 "1800" -54572 "1810" -50919 "1820" -47266 "1830"		///
						 -43613 "1840" -39960 "1850" -36307 "1860", labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}	

	}
	
restore

*** The main analyses focus on two DVs: (1) the state average ideal point, with
*** state fixed effects (avoiding problems of unobserved constituency changes), 
*** and (2) the district level ideal point, with fixed effects at the unique district
*** level. This would be preferable, but potentialy includes unobserved district changes. 
*** The number of districts unchanged before/after reform is also reduced.
*** The supplemental material includes a forward/lagging indicator and an analysis
*** of the probability of electing Democrats (or equivalent)
preserve
	*** Set panel data to state level
	xtset icpsrstate
	*** What is the probability of electing a Democrat (or equivalent)
	eststo suppl_1: xtreg demFull i.category i.decade, fe cluster(icpsrstate)
	estadd local fixed "State"
	eststo suppl_2: xtreg demFull i.category i.decade if congress>=19, fe cluster(icpsrstate)
	estadd local fixed "State"

	*** Get the mean and 1 SDs of adjusted ideal points, for graphing purposes.
	qui summ adjust_d1, det
	loc k1 = r(sd)
	loc k2 = r(mean)
	loc y1 = round(`k2'-(2*`k1'),0.01)
	loc y2 = round(`k2'+(2*`k1'),0.01)
	
	*** Get the average ideal points for each state/congress.
	collapse adjust_d1 demFull fedFull category decade, by(icpsrstate congress)
	xtset icpsrstate congress
	
	*** What is the effect of franchise reform on state-level ideal points
	eststo main_1: xtreg adjust_d1 i.category i.decade, fe cluster(icpsrstate)
	estadd local fixed "State"
	
	margins, over(category)
		marginsplot, recast(scatter) xsc(reverse) name(graph1, replace) ///
		plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black)) yline(`k2', lp(dash) lc(black) lw(thin))	///
		graphreg(col(white)) ylabel(`y1'(0.5)`y2', nogrid angle(h) labsize(vsmall)) ytitle("Ideal Point Scale")	///
		xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vsmall))	title("`x'", size(small) col(black) )	///
		note("Dashed line indicates chamber mean. The y-axis runs from two standard deviations above and below the mean.", size(vsmall))
	
	*** What is the effect of franchise reform on state-level ideal points, distinguishing
	*** between early Republic and antebellum era.
	eststo main_2: xtreg adjust_d1 i.category i.congress if congress<=17, fe 
	estadd local fixed "State"
	eststo main_3: xtreg adjust_d1 i.category i.congress if congress>=19, fe 	
	estadd local fixed "State"
	
	*** Forward and lagging indicators of franchise reform.
	eststo suppl_fw4: xtreg adjust_d1 F4.i.category i.congress, fe 
	eststo suppl_fw3: xtreg adjust_d1 F3.i.category i.congress, fe 
	eststo suppl_fw2: xtreg adjust_d1 F2.i.category i.congress, fe 
	eststo suppl_fw1: xtreg adjust_d1 F1.i.category i.congress, fe 
	eststo suppl_lag1: xtreg adjust_d1 L1.i.category i.congress, fe 
	eststo suppl_lag2: xtreg adjust_d1 L2.i.category i.congress, fe 
	eststo suppl_lag3: xtreg adjust_d1 L3.i.category i.congress, fe 
	eststo suppl_lag4: xtreg adjust_d1 L4.i.category i.congress, fe 
	
restore

*** Reset panel structure to the unique district
xtset unique_id 
*** For stable districts (same pre/post reform), what is the effect of franchise
*** qualifications on ideal points.
eststo main_4: xtreg adjust_d1 i.category i.decade, fe vce(cluster icpsrstate)
estadd local fixed "District"

********************************************************************************
************************		Figures and Table 		************************
********************************************************************************
****************				Main Text 				************************
*** Table 7: Franchise qualifications and congressional ideal points
esttab main_1 main_2 main_3 main_4 using "Tables\Table-7.tex", se(a2)  label 	///
	title(Franchise Qualifications and Congressional Ideal Points) 	///
	drop( _cons *.decade *.congress 0.category ) nonumbers 	///
	coeflabels(1.category "Medium Threshold ($\beta_{1}$)" 2.category "High Threshold ($\beta_{2}$)")	///
	mgroups("State Models" "District Model" , pattern(1 0 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("1788-1859" "1788-1821" "1824-1859" "1788-1859") nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(fixed N_g N, fmt(%9.0g) label("Fixed effects" "Clusters" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:7} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{Robust standard errors, clustered at the state level for district-level model. Controls for congressional session included in all models.} \end{table}) substitute(\_ _) tex   replace

*** Figure 7: State average congressional ideal points over time.
graph combine Delaware Maryland NewJersey SouthCarolina Connecticut Massachusetts NewYork Virginia RhodeIsland Louisiana AllOtherStates combined_ideal, cols(4) imargin(none) ///
	graphreg(col(white)) ycommon l1title("Ideal Point Scale", size(vsmall)) 	///
	note("Dashed vertical lines mark effective reform date. Higher values associated with Federalists/Whigs/Republicans.""Bottom right panel shows years from reform.", size(vsmall)) 
graph export "Figures\Figure-7.pdf", replace 

****************			Supplemental Material			********************
*** Tables
*** Table A16: Probability of electing a Democrat
esttab suppl_1 suppl_2 using "Tables\Supplemental\Supplemental-Table-16.tex", se(a2)  label 	///
	title(Franchise Qualifications and the Probability of Electing a Democrat) 	///
	drop( _cons *.decade 0.category ) nonumbers 	///
	coeflabels(1.category "Medium Threshold ($\beta_{1}$)" 2.category "High Threshold ($\beta_{2}$)")	///
	mgroups("Democrat" "Democrat", pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("1788-1859" "1824-1859") nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(fixed N_g N, fmt(%9.0g) label("Fixed effects" "Clusters" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:A16} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \multicolumn{@span}{p{.8\textwidth}}{\footnotesize Robust standard errors, clustered at the state level for district-level model. Controls for congressional session included in all models. }	///
	\end{tabular} \end{table}) substitute(\_ _) tex   replace

*** Table A17: Effect of Franchise Qualifications on Congressional Ideal Points, 
*** using forward and lagged indicators.
esttab  suppl_fw4 suppl_fw3 suppl_fw2 suppl_fw1 main_1 suppl_lag1 suppl_lag2 suppl_lag3 suppl_lag4 , ///
	cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(*.category) drop(0*.category)	///
	rename(1F4.category 1.category 1F3.category 1.category 1F2.category 1.category 1F.category 1.category	///
			2F4.category 2.category 2F3.category 2.category 2F2.category 2.category 2F.category 2.category 	///
			1L4.category 1.category 1L3.category 1.category 1L2.category 1.category 1L.category 1.category	///
			2L4.category 2.category 2L3.category 2.category 2L2.category 2.category 2L.category 2.category) replace  		
capture mat drop C
matrix C = r(coefs)
*eststo clear
local rnames : rownames C
local models : coleq C
local models : list uniq models
local i 0
foreach name of local rnames {
	local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
        local ++j
        matrix tmp = C[`i', 2*`j'-1]
        if tmp[1,1]<. {
            matrix colnames tmp = `model'
            matrix b = nullmat(b), tmp
            matrix tmp[1,1] = C[`i', 2*`j']
            matrix se = nullmat(se), tmp
        }
    }
    ereturn post b
    quietly estadd matrix se
    eststo name`i'
}

esttab name1 name2 using  "Tables\Supplemental\Supplemental-Table-17.tex", 	///
	wide se(a2) b(a2) label title(Effect of Franchise Qualifications on Congressional Ideal Points) 		///
	mtitles("Medium" "High") nogaps nodepvars nostar compress noconstant nonotes nonumbers 					///
	coeflabels( suppl_fw4 "Forward 4 Congresses" suppl_fw3 "Forward 3 Congresses" suppl_fw2 "Forward 2 Congresses" suppl_fw1 "Forward 1 Congress" main_1 "Franchise Reform Congress" suppl_lag1 "Lagged 1 Congress" suppl_lag2 "Lagged 2 Congresses" suppl_lag3 "Lagged 2 Congresses" suppl_lag4 "Lagged 2 Congresses")	///
	stats() noobs nolines prehead(\begin{table}[hbt!]\centering	\caption{Franchise Qualifications and Ideal Points} \label{tab:A17} ///
	\begin{tabular}{l*{6}{c}} \toprule)	posthead(\midrule) prefoot(\midrule)  													///
	postfoot(\bottomrule \multicolumn{@span}{p{.6\textwidth}}{\footnotesize State and Congress FE in all models.}	///
	\end{tabular} \end{table})   tex replace
		
*** Figure A10: Marginal effects of different suffrage qualifications.
graph display graph1
graph export "Figures\Supplemental\Supplemental-Figure-10.pdf", replace 
	